Caches speed access to data by using hierarchies of memory. The memory generally includes combinations of faster memory (generally higher cost) and slower memory (generally lower cost). An example of faster memory may include volatile memory such as random access memory (RAM). An example of slower memory may include non-volatile memory such as a hard disk.
If a computer system receives a request to read or write data corresponding with a memory block, the system may first check whether the requested block is cached, meaning whether the cache contains a copy of the corresponding data. If the requested block is cached, the system may perform the requested read or write operation on the cached copy stored in the faster memory, without having to wait for the slower memory.
For example, if the system receives a read request, the system may fulfill the read request by retrieving the cached data from the faster memory instead of the slower memory. In response to a read request, a “cache read hit” indicates that the cache contains data corresponding to a requested block. A “cache read miss” indicates the cache does not contain the requested data, and so the system must read the requested data from slower storage.
Similarly, if the system receives a write request, the system may update a cached copy in the faster memory and complete the requested operation, without having to wait for the slower memory to update. In response to a write request, a “cache write hit” indicates that the cache contains the requested block, and so the system may proceed to update the faster memory without having to wait for the slower memory. The system may then choose either to proceed to write to the slower memory, or defer writing to the slower memory, perhaps until the system has batched a number of write operations for efficiency. A “cache write miss” indicates the cache does not contain the requested data, and so the system must update the slower memory.